

package io.renren.modules.app.controller;


import io.renren.common.utils.R;
import io.renren.common.utils.MyRandomCode;
import io.renren.common.validator.ValidatorUtils;
import io.renren.modules.app.entity.MemberGradeEntity;
import io.renren.modules.app.entity.UserEntity;
import io.renren.modules.app.form.RegisterForm;
import io.renren.modules.app.service.MemberGradeService;
import io.renren.modules.app.service.MemberPurseService;
import io.renren.modules.app.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * 注册
 *
 * @author Travel
 */
@RestController
@RequestMapping("/app")
@Api("APP注册接口")
public class UserRegisterController {
    @Autowired
    private UserService userService;


    @PostMapping("register")
    @ApiOperation("注册")
    public R register(@RequestBody RegisterForm form) {
        UserEntity userEntity = userService.queryByMobile(form.getMobile());
        if (userEntity != null) {
            return R.error("该号码已注册过，请更换号码");
        }
        Integer register = userService.register(form);
        if (register > 0) {
            return R.ok();
        } else {
            return R.error("注册失败，请稍后重试");
        }

    }

    public static void main(String[] args) {
        System.out.println(MyRandomCode.generateNumbers());
    }
}
